package com.qy.controller.app;

import com.qy.base.core.Result;
import com.qy.base.core.ResultGenerator;
import com.qy.model.CopyWriting;
import com.qy.service.CopyWritingService;
import com.qy.base.core.PageBean;
import com.github.pagehelper.PageHelper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by zaq on 2018/07/10.
 */
@RestController
@RequestMapping("app/copy/writing")
public class CopyWritingController {
    @Resource
    private CopyWritingService copyWritingService;

    @PostMapping("/add")
    public Result add(@RequestBody CopyWriting copyWriting) {
        copyWritingService.save(copyWriting);
        return ResultGenerator.successResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody Integer id) {
        copyWritingService.deleteById(id);
        return ResultGenerator.successResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody CopyWriting copyWriting) {
        copyWritingService.update(copyWriting);
        return ResultGenerator.successResult();
    }

    @GetMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        CopyWriting copyWriting = copyWritingService.findById(id);
        return ResultGenerator.successResult(copyWriting);
    }

    @GetMapping("/list")
    public Result list(PageBean<CopyWriting> page) {
        PageHelper.startPage(page.getPageNum(), page.getSize());
        List<CopyWriting> list = copyWritingService.findAll();
        page.setList(list);
        return ResultGenerator.successResult(page);
    }

    //文案详情
    @GetMapping("/copyWritingDetail")
    public Result copyWritingDetail() {
        List<CopyWriting> list = copyWritingService.findAll();
        return ResultGenerator.successResult(list);
    }
}
